package com.ys.otms.utils.download.impl;


import com.ys.otms.utils.download.IDownloadHandler;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.util.CellRangeAddress;


public abstract class DefaultDownloadHandler implements IDownloadHandler {

    public void dealReportHeader(HSSFWorkbook wb, HSSFSheet sheet) {
        String[] headers = getReportHeader();
        Integer[] widths = getReportWidth();
        // header
        HSSFRow rowHeader = sheet.createRow(0);
        CellRangeAddress cra=new CellRangeAddress(0, 0, 0, 5);
        sheet.addMergedRegion(cra);

        HSSFCellStyle style = wb.createCellStyle();
        style.setAlignment(HorizontalAlignment.CENTER);
        style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        style.setFillForegroundColor(HSSFColor.DARK_GREEN.index);
        HSSFPalette palette = wb.getCustomPalette();
        palette.setColorAtIndex(Short.parseShort("10"), (byte) 0x9B, (byte) 0xBB, (byte) 0x59);
        style.setFillForegroundColor(Short.parseShort("10"));
        HSSFFont font = wb.createFont();
        font.setFontHeightInPoints(Short.parseShort("10"));
        font.setBold(true);
        font.setColor(HSSFColor.WHITE.index);
        style.setFont(font);
        for (int i = 0; i < headers.length; i++) {
            HSSFCell cell = rowHeader.createCell(i);
            cell.setCellValue(headers[i]);
            cell.setCellStyle(style);
            sheet.setColumnWidth(i, i < widths.length ? widths[i] : 6000);
        }
    }
}